#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#ifdef __cplusplus
 extern "C" {	 
#endif
	 
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
  #include <stdint.h>
  extern uint32_t SystemCoreClock;
#endif

#define configUSE_PREEMPTION        1 //配置为1则为抢占式调度器0为合作式调度
#define configCPU_CLOCK_HZ          ( SystemCoreClock )//此参数用于定义CPU主频单位Hz
#define configTICK_RATE_HZ          ( ( TickType_t ) 1000 )//系统时钟节拍数，一般是1000就是系统滴答定时器为1ms
#define configMAX_PRIORITIES        ( 32 )//最大优先级设置
#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 128 )//空闲任务栈空间大小
#define configTOTAL_HEAP_SIZE       ( ( size_t ) ( 100 * 1024 ) )//RTOS内核堆大小
#define configMAX_TASK_NAME_LEN		( 16 )//定义任务名称的最长字符数
#define configUSE_16_BIT_TICKS		0//时钟节拍计数的类型，32位系统则禁用这个宏，使用32位数计数
#define configIDLE_SHOULD_YIELD		0//用于设置和空闲任务优先级相同的任务，这个不建议使用

#define configUSE_TASK_NOTIFICATIONS    1//使能任务间直接的消息传递，包括信号量，事件标志组和消息邮箱
#define configUSE_MUTEXES               1//使用互斥量
#define configUSE_RECURSIVE_MUTEXES     1//使用递归互斥信号量
#define configUSE_RECURSIVE_MUTEXES     1//使用计数信号量
#define configQUEUE_REGISTRY_SIZE       32//这个用来设置可以注册的信号量和消息队列的个数（如果没有内核方面的调试器，这个宏定义是没有意义的）
#define configUSE_QUEUE_SETS            1//使能消息队列  
#define configUSE_TIME_SLICING          1//使能时间片调度，没有定义的化，默认就是1
#define configUSE_NEWLIB_REENTRANT      0//配置为1每个任务创建的时候将分配 Newlib 的重入结构体

#define configUSE_IDLE_HOOK             1//使能空闲任务的钩子函数
#define configUSE_MALLOC_FAILED_HOOK	1//动态内存申请失败时候的钩子函数
#define configUSE_TICK_HOOK             1//使能滴答定时器中断中执行的钩子函数

#define configCHECK_FOR_STACK_OVERFLOW	2//栈溢出检测的支持方法
//#define configGENERATE_RUN_TIME_STATS	  1//使能任务运行状态统计(一般统计的时基要是系统ticks的10-20倍才能统计正确)
//#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() (CPU_RunTime = 0ul) //和configGENERATE_RUN_TIME_STATS同时使用
//#define portGET_RUN_TIME_COUNTER_VALUE() CPU_RunTime //


#define configUSE_TRACE_FACILITY                1//使能此配置将添加额外的结构体成员和函数， 以此来协助可视化和跟踪
#define configUSE_STATS_FORMATTING_FUNCTIONS    1//将使能函数 vTaskList() 和 vTaskGetRunTimeStats() 配合configUSE_TRACE_FACILITY使用

#define configUSE_TIMERS                        1//使能软件定时器
#define configTIMER_TASK_PRIORITY               ( 2 )//定时器任务的优先级
#define configTIMER_QUEUE_LENGTH                10//软件定时器命令队列的长度
#define configTIMER_TASK_STACK_DEPTH            ( configMINIMAL_STACK_SIZE * 2 )//软件定时器的任务的栈空间大小

#define configUSE_APPLICATION_TASK_TAG	0
#define configUSE_COUNTING_SEMAPHORES	1


/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet            1
#define INCLUDE_uxTaskPriorityGet           1
#define INCLUDE_vTaskDelete                 1
#define INCLUDE_vTaskCleanUpResources       1
#define INCLUDE_vTaskSuspend			    1
#define INCLUDE_vTaskDelayUntil             1
#define INCLUDE_vTaskDelay                  1

/*********************************************************************************************************************************/
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
	/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
	#define configPRIO_BITS       		__NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4        /* 15 priority levels */
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			0xf //此宏定义是用来配置 FreeRTOS 用到的 SysTick 中断和 PendSV 中断的优先级

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	1 //此宏定义比较重要， 定义了受 FreeRTOS 管理的最高优先级中断(处理滴答定时器其他硬中断不能是0组)

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/*********************************************************************************************************************************/

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
//#define xPortSysTickHandler SysTick_Handler

#ifdef __cplusplus
}
#endif
#endif /* FREERTOS_CONFIG_H */

